﻿// See https://aka.ms/new-console-template for more information
using System;
using System.Collections.Generic;
//action.Invoke()/action()
//委托:Action没有返回值  Func返回值在最后   函数指针升级版本
//声明委托
//namespace shh
//{
//    //声明委托,委托本身就是一个类
//    public delegate double Cal(double a, double b);
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            //Type t = typeof(Cal);
//            //Console.WriteLine(t.IsClass);

//            Calculate calculate = new Calculate();
//            Action action = calculate.Report;
//            Func<int, int, double> func = calculate.Sum;
//            action.Invoke();

//            double z = 0;
//            z=func(1, 2);
//            Console.WriteLine(z);

//            Cal cal = calculate.div;
//            z = cal(6.6, 2);
//            Console.WriteLine(z);
//        }

//    }

//    class Calculate
//    {
//        public void Report()
//        {
//            Console.WriteLine("three");
//        }

//        public double Sum(int x,int y)
//        {
//            return (double)x + y;
//        }
//        public int Sub(int x, int y)
//        {
//            return x - y;
//        }

//        public double div(double x, double y)
//        {
//            return x / y;
//        }
//    }
//}


//间接调用委托:模板方法
namespace shh
{
    class Program
    {
        static void Main(string[] args)
        {
            Factory factory = new Factory();

        }
    }
    class Product
    {
        public string Name { get; set; }
    }

    class Box
    {
        public Product product { get; set; }
    }
    class WrapFactory
    {
        public Box WrapProduct(Func<Product> Product)
        {
            Box box = new Box();    
            Product product = new Product();
            box.product = product;
            return box;
        }
    }
    class Factory
    {
        public Product MakePizza()
        {
            Product product = new Product();
            product.Name = "Pizza";
            return product;
        }
        public Product MakeToyCar()
        {
            Product product = new Product();
            product.Name = "Toy Car";
            return product;
        }
    }
}